package com.mata.worktime.controller.work;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mata.worktime.controller.BaseController;
import com.mata.worktime.entity.BaseEntity;
import com.mata.worktime.entity.user.Dept;
import com.mata.worktime.entity.user.Post;
import com.mata.worktime.entity.user.Role;
import com.mata.worktime.entity.user.User;
import com.mata.worktime.entity.work.Member;
import com.mata.worktime.entity.work.Project;
import com.mata.worktime.entity.work.ProjectType;
import com.mata.worktime.service.user.DeptService;
import com.mata.worktime.service.user.PostService;
import com.mata.worktime.service.user.RoleService;
import com.mata.worktime.service.user.UserService;
import com.mata.worktime.service.work.MemberService;
import com.mata.worktime.service.work.ProjectService;
import com.mata.worktime.service.work.ProjectTypeService;
import com.mata.worktime.service.work.WorkHourService;
import com.mata.worktime.vo.LayuiTableVO;
import com.mata.worktime.vo.ResultVO;
import com.mata.worktime.vo.workhour.WorkHourTableVO;
import org.apache.commons.collections.list.AbstractLinkedList;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.mata.worktime.dto.WeekDTO;
import com.mata.worktime.dto.WorkHourParamDTO;
import com.mata.worktime.entity.work.WorkHour;
import com.mata.worktime.util.ExcelStyleUtil;
import com.mata.worktime.util.ExcelUtil;
import com.mata.worktime.util.WeekUtils;

import javax.lang.model.element.VariableElement;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

import static java.util.Comparator.comparingLong;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;


/**
 * 工时
 *
 * @author earthchen
 * @date 2018/9/29
 **/
@Controller
@RequestMapping("/workhours")
public class WorkHoursController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(WorkHoursController.class);

    @Autowired
    private WorkHourService workHourService;

    @Autowired
    private ProjectService projectService;

    @Autowired
    private PostService postService;

    @Autowired
    private UserService userService;

    @Autowired
    private DeptService deptService;

    @Autowired
    private RoleService roleService;

    @Autowired
    private ProjectTypeService projectTypeService;

    @Autowired
    private MemberService memberService;

    /**
     * 工时页面
     *
     * @return
     */
    @RequiresPermissions("system:workhours:view")
    @GetMapping("/view")
    public String workhours(Model model) {
        List<Long> proIds = new ArrayList<>();
        // 查询自己所在项目的项目id
        List<Member> members = memberService.list(new QueryWrapper<Member>().eq("user_id", getUserId())
                .select("user_id", "user_name", "pro_id", "join_time"));
        members.forEach(member -> proIds.add(member.getProId()));
        QueryWrapper<Project> eq = new QueryWrapper<Project>()
                .eq("status", "0")
                .eq("del_flag", "0");
        int isLeader = isLeader();
        // 如果角色中含有管理员
        if (isLeader >= 4) {
            model.addAttribute("projectList", projectService.list(eq));
            return "workhour/myworkhour";
        }
        getProIds(proIds, isLeader);//获取所属角色下的项目id
        if (proIds.size() == 0) {
            return "workhour/myworkhour";
        }
        eq.in("id", proIds);
        List<Project> projectList = projectService.list(eq);
        model.addAttribute("projectList", projectList);
        return "workhour/myworkhour";
    }

    /**
     * 工时审核页面
     *
     * @return
     */
    @RequiresPermissions("system:workhours:adminview")
    @GetMapping("/review")
    public String workHoursReview(Model model) {
        List<Long> proIds = new ArrayList<>();
        QueryWrapper<Project> eq = new QueryWrapper<Project>()
                .eq("status", "0")
                .eq("del_flag", "0");
        int isLeader = isLeader();
        // 如果角色中含有管理员
        if (isLeader >= 4) {
            model.addAttribute("projectList", projectService.list(eq));
            return "workhour/workHoursReview";
        }
        getProIds(proIds, isLeader);//获取所属角色下的项目id
        if (proIds.size() > 0) {
            eq.in("id", proIds);
        }
        List<Project> projectList = projectService.list(eq);
//        List<ProjectType> projectTypeList = projectTypeService.list(new QueryWrapper<>());
        model.addAttribute("projectList", projectList);
//        model.addAttribute("typeList", projectTypeList);
        return "workhour/workHoursReview";
    }


    private List<Long> getProIds(List<Long> proIds, int isLeader) {
        List<Long> deptIdList = new ArrayList<>();
        // 如果是项目经理
        if (isLeader == 1) {
            List<Project> projectList = projectService.list(new QueryWrapper<Project>().eq("status", "0")
                    .eq("del_flag", "0").eq("manager", getUserId().toString()));
            projectList.forEach(project -> proIds.add(project.getId()));
        }
        // 如果是部门经理
        if (isLeader == 2) {
            deptService.getAllChildrenDept(getUser().getDeptId()).forEach(dept -> deptIdList.add(dept.getId()));
            List<Project> projectList = projectService.list(new QueryWrapper<Project>().eq("status", "0")
                    .eq("del_flag", "0").in("dept_id", deptIdList));
            projectList.forEach(project -> proIds.add(project.getId()));
        }
        // 既是项目经理 也是 部门经理
        if (isLeader == 3) {
            deptService.getAllChildrenDept(getUser().getDeptId()).forEach(dept -> deptIdList.add(dept.getId()));
            List<Project> projectList = projectService.list(new QueryWrapper<Project>().eq("status", "0")
                    .eq("del_flag", "0").in("dept_id", deptIdList));
            projectList.forEach(project -> proIds.add(project.getId()));
            List<Project> projectList1 = projectService.list(new QueryWrapper<Project>().eq("status", "0")
                    .eq("del_flag", "0").eq("manager", getUserId().toString()));
            projectList1.forEach(project -> proIds.add(project.getId()));
        }
        return proIds.stream().distinct().collect(Collectors.toList());
    }

    /**
     * 领导或管理员查看页面
     *
     * @param model
     * @return
     */
    @GetMapping("/admin")
    @RequiresPermissions("system:workhours:adminview")
    public String adminWorkHour(Model model) {
        List<Long> proIds = new ArrayList<>();
        QueryWrapper<Project> eq = new QueryWrapper<Project>()
                .eq("status", "0")
                .eq("del_flag", "0");
        int isLeader = isLeader();
        // 如果角色中含有管理员
//        if (isLeader >= 4) {
//            model.addAttribute("projectList", projectService.list(eq));
//            return "workhour/admin";
//        }
        // 查询自己所在项目的项目id
//        List<Member> members = memberService.list(new QueryWrapper<Member>().eq("user_id", getUserId().toString())
//                .select("user_id", "user_name", "pro_id", "join_time"));
//        members.forEach(member -> proIds.add(member.getProId()));
//        getProIds(proIds, isLeader);//获取所属角色下的项目id
//        if (proIds.size() > 0) {
//            eq.in("id", proIds);
//        }
        List<Project> projectList = projectService.list(eq);
        model.addAttribute("projectList", projectList);
        return "workhour/admin";
    }

    /**
     * 分页获取自己工时数据
     *
     * @param paramDTO
     * @return
     */
    @RequiresPermissions("system:workhours:list")
    @GetMapping("/view/me")
    @ResponseBody
    public LayuiTableVO list(WorkHourParamDTO paramDTO) {
        Page<WorkHour> page = new Page<>(paramDTO.getPage(), paramDTO.getSize());
        WeekDTO weekDTO = new WeekDTO();
        if (paramDTO.getStartDate() == null && paramDTO.getEndDate() == null) {
            weekDTO = WeekUtils.getWeekDays(paramDTO.getWeekCode());
        } else {
            weekDTO.setStartDate(paramDTO.getStartDate());
            weekDTO.setEndDate(paramDTO.getEndDate());
        }
        QueryWrapper<WorkHour> entityWrapper = new QueryWrapper<WorkHour>()
                .eq(getUser() != null, "user_id", getUserId())
                .eq("del_flag", "0")
                .between("work_date", weekDTO.getStartDate(), weekDTO.getEndDate());
        // 获取本周工时
        if (paramDTO.getProjectId() != null) {
            entityWrapper.eq("project_id", paramDTO.getProjectId());
        }
        workHourService.page(page, entityWrapper);
        List<WorkHour> workHourList = page.getRecords();
        List<WorkHourTableVO> workHourTableVOS = new ArrayList<>();
        for (WorkHour workHour : workHourList) {
            WorkHourTableVO workHourTableVO = new WorkHourTableVO();
            BeanUtils.copyProperties(workHour, workHourTableVO);
            // 设置周几
//            workHourTableVO.setWeekHour();
            workHourTableVOS.add(workHourTableVO);
        }
        return getTableInfo(workHourTableVOS, page.getTotal());
    }

    /**
     * 管理员或者部门经理查看自己部门员工的工时
     *
     * @param paramDTO
     * @return
     */
    @RequiresPermissions("system:workhours:adminlist")
    @ResponseBody
    @GetMapping("/admin/view")
    public LayuiTableVO view(WorkHourParamDTO paramDTO) {

        Page<WorkHour> page = new Page<>(paramDTO.getPage(), paramDTO.getSize());
        WeekDTO weekDTO = new WeekDTO();
        if (paramDTO.getStartDate() == null && paramDTO.getEndDate() == null) {
            weekDTO = WeekUtils.getWeekDays(paramDTO.getWeekCode());
        } else {
            weekDTO.setStartDate(paramDTO.getStartDate());
            weekDTO.setEndDate(paramDTO.getEndDate());
        }
        // 构造实体包装类
        QueryWrapper<WorkHour> entityWrapper = new QueryWrapper<WorkHour>()
                .eq("del_flag", "0")
                .between("work_date", weekDTO.getStartDate(), weekDTO.getEndDate())
                .orderByAsc("user_id");
        if (paramDTO.getProjectId() != null) {
            entityWrapper.eq("project_id", paramDTO.getProjectId());
        }
        //获得已经删除的用户
        QueryWrapper<User> userWrapper = new QueryWrapper<User>();
        userWrapper.eq("del_flag", "1");
        List<User> delUserList = userService.list(userWrapper);
        entityWrapper.notIn("user_id", delUserList.stream().map(User::getUserId).collect(Collectors.toSet()));

        // 查询工时
        page = getWorkHour(entityWrapper, paramDTO.getPage(), paramDTO.getSize(), paramDTO.getReviewFlag(),false);
        Set<String> collect = page.getRecords().stream().map(WorkHour::getUserId).collect(Collectors.toSet());

        // 当前所有被查询到的用户列表
        List<User> userList = userService.list(new QueryWrapper<User>()
                .in("id",
                        page.getRecords().stream().map(WorkHour::getUserId).collect(Collectors.toSet()))

        );
        // 构造id-user映射map
        Map<String, User> map = userList.stream().collect(Collectors.toMap(User::getId, user -> user));

        List<WorkHourTableVO> workHourTableVOS = new ArrayList<>();
        for (WorkHour workHour : page.getRecords()) {
            WorkHourTableVO workHourTableVO = new WorkHourTableVO();
            BeanUtils.copyProperties(workHour, workHourTableVO);
            // 设置用户名
            workHourTableVO.setUsername(map.get(workHour.getUserId()).getUserName());
            // 设置周几
//            workHourTableVO.setWeekHour();
            workHourTableVOS.add(workHourTableVO);
        }

        return getTableInfo(workHourTableVOS, page.getTotal());
    }

    // 根据角色不同获取不同数据
    private Page<WorkHour> getWorkHour(QueryWrapper<WorkHour> entityWrapper, int page, int size, String reviewFlag,boolean isExport) {
        Page<WorkHour> page1 = new Page<>(page, size);
        // 存储要查询的userid
        List<String> userIdList = new ArrayList<>();
        // 保存当前部门层级下所有用户信息
        List<User> deptUserList = new ArrayList<>();
        // 是否项目经理的标志
        int isLeader = isLeader();
        isLeader = 4;//普通角色可以相互查看
        // 判断当前是否是管理员
//        如果是管理员
        // 如果参数有审核状态，添加审核状态条件
        if (isLeader > 3) {
            if (reviewFlag != null && !reviewFlag.equals("")) {
                if (reviewFlag.equals("review")) {
                    entityWrapper.ne("review_flag", "1");
                } else {
                    entityWrapper.eq("review_flag", reviewFlag);
                }
            }
            if(isExport){
                page1.setRecords(workHourService.list(entityWrapper));
            }else {
                workHourService.page(page1, entityWrapper);
            }
        } else {
            if (reviewFlag != null && !reviewFlag.equals("")) {
                if (reviewFlag.equals("review")) {
                    entityWrapper.ne("review_flag", "1");
                } else {
                    entityWrapper.eq("review_flag", reviewFlag);
                }
            }
        }

        // 只是项目经理
        if (isLeader == 1) {
            userIdList.add(getUserId());
            List<Long> projectIds = new ArrayList<>();
            // 查询出拥有管理权的项目
            List<Project> projects = projectService.list(new QueryWrapper<Project>().eq("manager", getUserId()));
            if (projects.size() != 0) {
                for (Project project : projects) {
                    projectIds.add(project.getId());
                }
                // 查询条件加上自己管理的项目id
                entityWrapper.in("project_id", projectIds);
                // 查询自己管理的项目成员
                List<Member> members = memberService.list(new QueryWrapper<Member>()
                        .in("pro_id", projectIds)
                        .select("user_id", "user_name", "pro_id", "join_time"));
                for (Member member : members) {
                    userIdList.add(member.getUserId());
                }
                entityWrapper.in("user_id", userIdList.stream().distinct().collect(Collectors.toList()));
                if(isExport){
                    page1.setRecords(workHourService.list(entityWrapper));
                }else {
                    workHourService.page(page1, entityWrapper);
                }
            }
        }
        // 只是部门经理的
        if (isLeader == 2) {
            String deptId = getUser().getDeptId();
            getDeptUser(deptId, deptUserList);
            userIdList.addAll(deptUserList.stream().map(User::getId).collect(Collectors.toList()));
            //查询所属项目中所有用户的工时
            entityWrapper.in("user_id", userIdList.stream().distinct().collect(Collectors.toList()));
            if(isExport){
                page1.setRecords(workHourService.list(entityWrapper));
            }else {
                workHourService.page(page1, entityWrapper);
            }
        }

        // 既是项目经理又是部门经理的
        if (isLeader == 3) {
            userIdList.add(getUserId());
            List<String> deptUserIdList = new ArrayList<>();
            deptUserIdList.add(getUserId());
            String deptId = getUser().getDeptId();
            getDeptUser(deptId, deptUserList);
            //部门下所有用户的id
            deptUserIdList.addAll(deptUserList.stream().map(User::getId).collect(Collectors.toList()));

            List<Long> projectIds = new ArrayList<>();
            List<Project> projects = projectService.list(new QueryWrapper<Project>().eq("manager", getUserId()));
            if (projects.size() != 0) {
                for (Project project : projects) {
                    projectIds.add(project.getId());
                }
                // 查询所拥有的项目的项目成员
                List<Member> members = memberService.list(new QueryWrapper<Member>()
                        .in("pro_id", projectIds)
                        .select("user_id", "user_name", "pro_id", "join_time"));
                for (Member member : members) {
                    userIdList.add(member.getUserId());
                }
            }
            //查询所属项目中所有用户的工时
            /*
             * ((user_id in (userIdList) and project_id in (projectIds)) or user_id in (deptUserIdList))
             *
             * */
            entityWrapper.and(workHourQueryWrapper -> workHourQueryWrapper.and(i ->
                    i.in("user_id", userIdList.stream().distinct().collect(Collectors.toList())).in("project_id", projectIds))
                    .or()
                    .in("user_id", deptUserIdList.stream().distinct().collect(Collectors.toList())));
            if(isExport){
                page1.setRecords(workHourService.list(entityWrapper));
            }else {
                workHourService.page(page1, entityWrapper);
            }
        }
        return page1;
    }


    private int isLeader() {
        List<Role> roles = roleService.selectRolesByUserId(getUserId());
        int isLeader = 0;
        for (Role role : roles) {
            if (role.isFlag()) {
                if (role.getRoleName().equals("项目经理")) {
                    isLeader += 1;
                }
                if (role.getRoleName().equals("部门经理")) {
                    isLeader += 2;
                }
                if (role.getRoleName().equals("管理员")) {
                    isLeader += 4;
                }
            }
        }
        return isLeader;
    }

    /**
     * 递归获取当前层级下所有用户的列表
     *
     * @param deptId       当前部门id
     * @param deptUserList 部门层级下的用户列表
     */
    private void getDeptUser(String deptId, List<User> deptUserList) {
        List<User> users = userService.list(new QueryWrapper<User>()
                .eq(deptId != null, "dept_id", deptId));
        if (users.isEmpty()) {
            return;
        }
        // 加入用户列表
        deptUserList.addAll(users);
        List<Dept> childDept = deptService.getChildrenDept(deptId);
        Set<Long> deptIdList = childDept.stream().map(BaseEntity::getId).collect(
                Collectors.toSet());

        for (Long id : deptIdList) {
            getDeptUser(id.toString(), deptUserList);
        }
    }

    /**
     * 批量增加工时
     *
     * @return
     */
    @RequiresPermissions("system:workhours:add")
    @PostMapping(value = "/add")
    @ResponseBody
    public ResultVO add(@RequestBody @Valid List<WorkHourTableVO> workHourTableVOS) {
        List<WorkHour> workHourList = new ArrayList<>();
        for (WorkHourTableVO workHourTableVO : workHourTableVOS) {
            // 将当前星期几填写的工时赋值给工时字段
//            workHourTableVO.weekToDayHour();
            WorkHour workHour = new WorkHour();
            BeanUtils.copyProperties(workHourTableVO, workHour);
            // 如果userid为空，说明为新增的
            if (workHour.getUserId() == null) {
                workHour.setUserId(getUserId());
            }
            workHourList.add(workHour);
        }
        return ResultVO.success(workHourService.saveOrUpdateBatch(workHourList));
    }

    /**
     * 批量更新工时
     *
     * @param workHours
     * @return
     */
    @RequiresPermissions("system:workhours:edit")
    @PutMapping("/updateBatch")
    @ResponseBody
    public ResultVO updateBatch(@RequestBody List<WorkHour> workHours) {
        workHours.forEach(workHour -> workHour.setUpdateTime(new Date()));
        return ResultVO.success(workHourService.updateBatchById(workHours));
    }

    /**
     * 更新工时
     *
     * @param workHour
     * @return
     */
    @RequiresPermissions("system:workhours:edit")
    @PutMapping("/update/{workHourId}")
    @ResponseBody
    public ResultVO update(@PathVariable("workHourId") Long workHourId, @RequestBody WorkHour workHour) {
        workHour.setId(workHourId);
        workHour.setUpdateTime(new Date());
        return ResultVO.success(workHourService.updateById(workHour));
    }


    /**
     * 删除指定id的工时(物理删除)
     *
     * @param workHourId
     * @return
     */
    @RequiresPermissions("system:workhours:delete")
    @DeleteMapping("/del/{workHourId}")
    @ResponseBody
    public ResultVO del(@PathVariable("workHourId") Long workHourId) {
        return ResultVO.success(workHourService.removeById(workHourId));
    }

    /**
     * 管理员删除指定id的工时(逻辑删除)
     *
     * @param workHourId
     * @return
     */
    @RequiresPermissions("system:workhours:admindelete")
    @DeleteMapping("/admin/del/{workHourId}")
    @ResponseBody
    public ResultVO adminDel(@PathVariable("workHourId") Long workHourId) {
        WorkHour workHour = new WorkHour();
        workHour.setId(workHourId);
        workHour.setDelFlag("1");
        return ResultVO.success(workHourService.updateById(workHour));
    }

    /**
     * 管理员批量删除指定id的工时(逻辑删除)
     *
     * @param idList
     * @return
     */
    @RequiresPermissions("system:workhours:batchdelete")
    @DeleteMapping("/admin/batch/del")
    @ResponseBody
    public ResultVO adminBatchDel(@RequestBody List<Long> idList) {
        List<WorkHour> workHourList = idList.stream().map(id -> {
            WorkHour workHour = new WorkHour();
            workHour.setId(id);
            workHour.setDelFlag("1");
            return workHour;
        }).collect(Collectors.toList());

        return ResultVO.success(workHourService.updateBatchById(workHourList));
    }

    /**
     * 管理员导出
     */
    @RequiresPermissions("system:workhours:adminexcel")
    @GetMapping("/admin/excel")
    public void adminExportData(WorkHourParamDTO paramDTO,
                                HttpServletResponse response) {

        WeekDTO weekDTO = new WeekDTO();
        if (paramDTO.getStartDate() == null && paramDTO.getEndDate() == null) {
            weekDTO = WeekUtils.getWeekDays(paramDTO.getWeekCode());
        } else {
            weekDTO.setStartDate(paramDTO.getStartDate());
            weekDTO.setEndDate(paramDTO.getEndDate());
        }

        // 构造实体包装类
        QueryWrapper<WorkHour> entityWrapper = new QueryWrapper<WorkHour>()
                .eq("del_flag", "0")
                .between("work_date", weekDTO.getStartDate(), weekDTO.getEndDate());

        if (paramDTO.getProjectId() != null) {
            entityWrapper.eq("project_id", paramDTO.getProjectId());
        }

        //获得已经删除的用户
        QueryWrapper<User> userWrapper = new QueryWrapper<User>();
        userWrapper.eq("del_flag", "1");
        List<User> delUserList = userService.list(userWrapper);
        entityWrapper.notIn("user_id", delUserList.stream().map(User::getUserId).collect(Collectors.toSet()));
//        entityWrapper.orderByAsc("review_Flag");
        entityWrapper.orderByAsc("user_id");
        entityWrapper.orderByAsc("work_date");
        List<WorkHour> workHourList = getWorkHour(entityWrapper, paramDTO.getPage(), paramDTO.getSize(), paramDTO.getReviewFlag(), true).getRecords();
        // 当前所有被查询到的用户列表
        List<User> userList = userService.list(new QueryWrapper<User>()
                .in("id",
                        workHourList.stream().map(WorkHour::getUserId).collect(Collectors.toSet())));
        // 构造id-user映射map
        Map<String, User> userMap = userList.stream().collect(
                Collectors.toMap(User::getId, user -> user));
        // 所有的项目id
        List<Long> projecIds = workHourList.stream().map(WorkHour::getProjectId).collect(
                Collectors.toList());
        // 查询所有id的项目信息
        List<Project> projectList = projectService.list(new QueryWrapper<Project>()
                .in("id", projecIds));
        // 构造id-project映射map
        Map<Long, Project> projectMap = projectList.stream().collect(
                Collectors.toMap(Project::getId, project -> project));
        // 查询所有项目类型
//        List<ProjectType> typeList = projectTypeService.list(new QueryWrapper<>());
//        // 构造类型id-type映射map
//        Map<Long, ProjectType> typeMap = typeList.stream().collect(
//            Collectors.toMap(ProjectType::getId, type -> type));

        List<WorkHourTableVO> workHourTableVOS = new ArrayList<>();
        for (WorkHour workHour : workHourList) {
            WorkHourTableVO workHourTableVO = new WorkHourTableVO();
            BeanUtils.copyProperties(workHour, workHourTableVO);
            // 设置用户名
            workHourTableVO.setUsername(userMap.get(workHour.getUserId()).getUserName());
            workHourTableVO.setProjectName(
                    projectMap.get(workHour.getProjectId()).getProjectName());
//            workHourTableVO.setProjectTypeName(
//                typeMap.get(workHour.getProjectTypeId()).getTypeName());
            workHourTableVOS.add(workHourTableVO);
        }
        workHourTableVOS.forEach(workHourTableVO -> {
            if(workHourTableVO.getReviewFlag().equals("0")){
                workHourTableVO.setReviewFlag("未审核");
            }
            if(workHourTableVO.getReviewFlag().equals("1")){
                workHourTableVO.setReviewFlag("审核通过");
            }
            if(workHourTableVO.getReviewFlag().equals("2")){
                workHourTableVO.setReviewFlag("审核失败");
            }
        });
        ExportParams exportParams = new ExportParams("工时查看", "统计", ExcelType.XSSF);
        exportParams.setStyle(ExcelStyleUtil.class);
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams,
                WorkHourTableVO.class, workHourTableVOS);
        try {
            ExcelUtil.export(response, workbook, "工时查看");
        } catch (Exception e) {
            logger.error("excel导出错误");
        }
    }

}
